<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>生产登记审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <!--搜索开始-->
            <fieldset class="layui-elem-field layuimini-search">
                <legend>搜索信息</legend>
                <div style="margin: 10px 10px 10px 10px">
                    <form class="layui-form layui-form-pane" action="" id="searchFrm">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                            	<label class="layui-form-label">产品名称</label>
                            	<div class="layui-input-inline">
                            		<div class="layui-input-inline">
                            			<input type="text" name="product_name" id="product_name" class="layui-input">
                            		</div>
                            	</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-block" style="text-align: center;">
                                <a class="layui-btn " lay-submit="" lay-filter="data-search-btn"><label
                                        class="layui-icon layui-icon-search"></label>搜索</a>
                                <a class="layui-btn layui-btn-warm" onclick="javascript:$('#searchFrm')[0].reset()"
                                    lay-filter="data-search-btn"><label
                                        class="layui-icon layui-icon-refresh"></label>重置</a>
                            </div>
                        </div>
                    </form>
                </div>
            </fieldset>
            <!--搜索结束-->

            <!--表格开始-->
            <table class="layui-hide" id="RecordTable" lay-filter="RecordTable"></table>
            <div style="display: none;" type="text/html" id="RecordToolBar">
                <a class="layui-btn provider_btn_add layui-btn-sm" lay-event="pass"><label
                                    class="layui-icon layui-icon-add-1"></label>批量审核通过</a>
                <a class="layui-btn provider_btn_batchdelete layui-btn-sm layui-btn-danger data-count-delete"
                    lay-event="nopass"><label
                    class="layui-icon layui-icon-delete"></label>批量审核不通过</a>
            </div>
            <div style="display: none;" type="text/html" id="providerTableBar">
                <a class="layui-btn provider_btn_update layui-btn-xs layui-btn-warm data-count-delete"
                    lay-event="pass1">审核通过</a>
                <a class="layui-btn provider_btn_delete layui-btn-xs layui-btn-danger data-count-delete"
                    lay-event="nopass1">审核不通过</a>
            </div>
            <!--  是否可用 选择  -->
            <script type="text/html" id="availableTpl">
                <!-- 这里的 checked 的状态只是演示 -->
            <input type="checkbox" name="available" value="{{d.id}}" lay-skin="switch" lay-text="可用|不可用"
                lay-filter="availableSwitch" {{ d.available == 1 ? 'checked' : '' }}>
            </script>
            <!--表格结束-->

            <!--添加和修改的弹出层开始-->
            <div id="addOrUpdateDiv" style="display: none;padding: 0.3125rem">
                <form method="post" class="layui-form layui-form-pane" lay-filter="dataFrm" id="dataFrm">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">供应商名称</label>
                            <div class="layui-input-inline">
                                <!-- 做修改 -->
                                <input type="hidden" name="id" />
                                <input type="text" name="providername" lay-verify="required" placeholder="请输入供应商名称"
                                    autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">公司电话</label>
                            <div class="layui-input-inline">
                                <input type="text" name="telephone" placeholder="请输入公司电话" autocomplete="off"
                                    class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">邮编</label>
                            <div class="layui-input-inline">
                                <input type="text" name="zip" placeholder="请输入邮编" autocomplete="off"
                                    class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">公司地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="address" lay-verify="title" autocomplete="off"
                                placeholder="请输入公司地址" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">联系人</label>
                            <div class="layui-input-inline">
                                <input type="text" name="connectionperson" lay-verify="required" placeholder="请输入供应商联系人"
                                    autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">联系人电话</label>
                            <div class="layui-input-inline">
                                <input type="text" name="phone" placeholder="请输入联系人电话" autocomplete="off"
                                    class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">邮箱</label>
                            <div class="layui-input-inline">
                                <input type="text" name="email" placeholder="请输入邮箱" autocomplete="off"
                                    class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">开户行</label>
                            <div class="layui-input-inline">
                                <input type="text" name="bank" lay-verify="required" placeholder="请输入供应商名称"
                                    autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">账号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="account" placeholder="请输入公司账号" autocomplete="off"
                                    class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">传真</label>
                            <div class="layui-input-inline">
                                <input type="text" name="fax" placeholder="请输入传真" autocomplete="off"
                                    class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="" style="text-align: center;">
                            <a class="layui-btn " lay-submit="" lay-filter="doSubmit"><label
                                    class="layui-icon layui-icon-release"></label>提交</a>
                            <a class="layui-btn layui-btn-warm" onclick="javascript:$('#dataFrm')[0].reset()"
                                lay-filter="data-search-btn"><label class="layui-icon layui-icon-refresh"></label>重置</a>
                        </div>
                    </div>
                </form>

            </div>
            <!--添加和修改的弹出层结束-->
        </div>
    </div>
    <script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <script src="../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
    <script src="../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
    <script src="../../lib/common/common.js" charset="utf-8"></script>

    <script>
        layui.use(['form', 'table', 'laydate', 'layer'], function () {
            var form = layui.form;
            var table = layui.table;
            var laydate = layui.laydate;
            var layer = layui.layer;
            var tableIns = table.render({
				elem: '#RecordTable',
				url: api6 + "record/selAllRecord?check_tag=S001-1",
				toolbar: "#RecordToolBar",
                cellMinWidth: true,
                height: 'full-220',
               cols: [[
                {type: "checkbox",  fixed: "left" ,width:150},
                {field: 'id', title: 'ID', align: "center",width:200},
                {field: 'procedureId',  title: '工序编号', align: "center",width:120},
                {field: 'procedureName',  title: '工序名称', align: "center",width:150},
                {field: 'regCount',  title: '登记次数', align: "center",width:120},
                {field: 'labourHourAmount',  title: '本次工时数', align: "center",width:150},
                {field: 'costPrice',  title: '单位工时成本', align: "center",width:150},
                {field: 'register',  title: '登记人', align: "center",width:180},
                {field: 'registerTime',  title: '登记时间', align: "center",width:180},
				{title: '操作', templet: '#providerTableBar', fixed: "right", align: "center",width:180}
				]],
				page: true
            });

            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                var params = $("#searchFrm").serialize();
				params.check_tag="S001-1";
                //执行搜索重载
                table.reload('RecordTable', {
                    page: {
                        curr: 1
                    },
                    url: api6 + 'record/selAllRecord?' + params
                });
                return false;
            });

            //监听表头的事件
            table.on('toolbar(RecordTable)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
                    case 'nopass':
                        nopass();
                        break;
                    case 'pass':
                        pass();
                        break;
                };
            });

            //监听行数据的事件
            table.on('tool(RecordTable)', function (obj) {
                var data = obj.data;
                if (obj.event === 'delete') {
                    layer.prompt({
                        formType: 1,
                        value: '',
                        maxlength: 6, //可输入文本的最大长度，默认500
                        title: '敏感操作，请输入口令'
                    }, function (value, index, elem) {
                        if (value == 'yby123') {
                            $.post(api6 + "provider/deleteProvider", {
                                id: data.id
                            }, function (res) {
                                layer.msg(res.msg);
                                obj.del();
                                layer.close(index);
                            })
                        } else {
                            layer.msg("口令错误");
                        }
                    });

                } else if (obj.event === 'update') {
                    pass1(data);
                } else if (obj.event === 'show') {
                    nopass1(data);
                }
            });


			//通過審核
			function pass1(data) {
				var params="";
				params += "ids=" + data.applyId;
			    params +="&checker=" + username;
			    $.post(api6 + "record/batchPass", params, function (res) {
			        layer.msg(res.msg);
			        tableIns.reload();
			        layer.close(index);
			    });
			}
			
			// 不通過審核
			function nopass1(data) {
				var params="";
				params += "ids=" + data.applyId;
			    params +="&checker=" + username;
			    $.post(api6 + "record/batchNoPass", params, function (res) {
			        layer.msg(res.msg);
			        tableIns.reload();
			        layer.close(index);
			    });
			}


            //监听可用操作
            form.on('switch(availableSwitch)', function (obj) {
                $.post(api6 + "provider/updateProvider", { id: this.value, available: obj.elem.checked ? 1 : 0 }, function (res) {
                    layer.msg(res.msg);
                    tableIns.reload();
                })
            });

            //打开添加供应商的弹层
            var mainIndex;
            var url; //动态的url
            function openAddProvider() {
                mainIndex = layer.open({
                    type: 1,
                    title: '添加供应商',
                    content: $("#addOrUpdateDiv"),
                    area: ['800px', '500px'],
                    success: function (index) {
                        url = api6 + "provider/addProvider";
                        //重置表单
                        $("#dataFrm")[0].reset();

                    }
                });
            }

            //提交数据
            form.on("submit(doSubmit)", function (data) {
                var btn = $(this);
                btn.text("提 交 中...").attr("disabled", "disabled").addClass("layui-disabled");
                var params = $("#dataFrm").serialize();
                $.post(url, params, function (res) {
                    layer.msg(res.msg);
                    if (res.code == 200) {
                        btn.text("提交").attr("disabled", "").removeClass("layui-disabled");
                        tableIns.reload();
                    }
                    layer.close(mainIndex);
                })
                return false;
            })
			
			//批量审核不通过
			function nopass() {
			    var checkStatus = table.checkStatus('RecordTable'); //idTest 即为基础参数 id 对应的值
			    var data = checkStatus.data;
			    var length = checkStatus.data.length;
			    console.log(checkStatus.data) //获取选中行的数据
			    console.log(checkStatus.data.length) //获取选中行数量，可作为是否有选中行的条件
			    if (length == 0) {
			        layer.msg("请选中不通过审核的行数据");
			    } else {
			        layer.prompt({
			            formType: 1,
			            value: '',
			            maxlength: 6, //可输入文本的最大长度，默认500
			            title: '敏感操作，请输入口令，防止杂毛'
			        }, function (value, index, elem) {
			            if (value == '123456') {
			                var params = "";
			                $.each(data, function (index, item) {
								console.log(item.id);
			                    if (index == 0) {
			                        params += "ids=" + item.id;
			                    } else {
			                        params += "&ids=" + item.id;
			                    }
			                });
							params +="&checker=" + username;
			                $.post(api6 + "record/batchNoPass", params, function (res) {
			                    layer.msg(res.msg);
			                    tableIns.reload();
			                    layer.close(index);
			                });
			            } else {
			                layer.msg("口令错误");
			            }
			        });
			    }
			}
			
			//批量审核通过
			function pass() {
			    var checkStatus = table.checkStatus('RecordTable'); //idTest 即为基础参数 id 对应的值
			    var data = checkStatus.data;
			    var length = checkStatus.data.length;
			    console.log(checkStatus.data) //获取选中行的数据
			    console.log(checkStatus.data.length) //获取选中行数量，可作为是否有选中行的条件
			    if (length == 0) {
			        layer.msg("请选中要通过审核的行数据");
			    } else {
			        layer.prompt({
			            formType: 1,
			            value: '',
			            maxlength: 6, //可输入文本的最大长度，默认500
			            title: '你是本人，请输入口令，防止杂毛'
			        }, function (value, index, elem) {
			            if (value == '123456') {
			                var params = "";
			                $.each(data, function (index, item) {
			                    if (index == 0) {
			                        params += "ids=" + item.id;
			                    } else {
			                        params += "&ids=" + item.id;
			                    }
			                });
							params +="&checker=" + username;
			                $.post(api6 + "record/batchPass", params, function (res) {
			                    layer.msg(res.msg);
			                    tableIns.reload();
			                    layer.close(index);
			                });
			            } else {
			                layer.msg("口令错误");
			            }
			        });
			    }
			}
		});
    </script>

</body>

</html>